define(function(require) {
	
	var $ = require("jquery1.7");
	
	var backManagerService = require("bean/backManagerService");
	var utils = require("utils");
	var ctx = utils.constants.ctx;
	var ui = require("ui");
	var BlackBox = require("blackbox");
	var blackBox = new BlackBox();
	
	$("#userApproved").bind("click",function(){
		blackBox.confirm("是否通过审核?",function(){
			var userId = $("#user_id").val();
			if(userId == null){
				return  false ;
			}
			try {
				ui.mask().show("请稍候...");
				backManagerService.userApproval(userId);
				ui.mask().hide();
				blackBox.alert("审核成功");
				location.href = ctx+"/back/base/userAuditList";
			} catch(e){
				ui.mask().hide();
				blackBox.alert("审核失败");
			}
		},{
			  title:'提示',
			  value:'确认'
		});
	});
	
	$("#userUnApproved").bind("click",function(){
		blackBox.confirm("是否不通过审核?",function(){
			var userId = $("#user_id").val();
			if(userId == null){
				return  false ;
			}
			try {
				ui.mask().show("请稍候...");
				backManagerService.userUnApproval(userId);
				ui.mask().hide();
				blackBox.alert("操作成功");
				location.href = ctx+"/back/base/userAuditList";
			} catch(e){
				ui.mask().hide();
				blackBox.alert("审核失败");
			}
		},{
			title:'提示',
			value:'确认'
		});
	});
	
	$("#auditUserList").bind("click",function(){
		if ($('input[name=items]:checkbox:checked').length <= 0) {
			blackBox.alert("请选择用户");
			return;
		}
		
		blackBox.confirm("确定这些用户通过审核?",function(isOk){
			if(isOk){
				var array = [];
				$('input[name=items]:checkbox:checked').each(function() {
					
					var id = $(this).attr("id").replace("user_", "");
					array.push(id);   
				});
				if (array.length != 0) {
					try{
						ui.mask().show("请稍候...");
						backManagerService.userApprovalList(array);
						ui.mask().hide();
						blackBox.alert("审核成功");
						location.href = ctx+"/back/base/userAuditList";
					} catch (e) {
						ui.mask().hide();
						blackBox.alert("审核失败:"+e.message);
					}
				} 
			}
		},{
			title:'提示',
			value:'确认'
		});
	});
	
	$("#searchBtn").bind("click",function(){
		var searchContent = $("#searchInfo").val();
		
		if(searchContent == null){
			blackBox.alert("请输入搜索内容")
			return false ;
		}
		ui.mask().show("请稍候...");
		location.href = ctx+"/back/base/userAuditList?username="+searchContent;
		
	});
	
	//取消审核
	$(document).on("click","#cancel",function(){
		location.href = ctx + "/back/base/userAuditList";
	});
	
	//用户审批详细
	$(document).on("click","#w_btn_href",function(){
		var userId=$(this).attr("data");
		location.href = ctx + "/back/base/userdetail?userId=" + userId;
	});
	
});